package me.baicai.modules.belldandy.gcb.domain;

import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import me.baicai.modules.system.domain.User;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;


/**
* @author 超级大白菜
* @date 2020-04-17
*/
@Entity
@Data
@Table(name="crm_order")
public class CrmOrder implements Serializable {

    // 订单号
    @Id
    @Column(name = "id")
    private String id;

    // 创建时间
    @Column(name = "created",nullable = false)
    private Date created;

    // 创建者ID
    @Column(name = "userid",nullable = false)
    private Long userid;

    // 项目编号
    @Column(name = "projectid",nullable = false)
    private Integer projectid;

    // 订单金额
    @Column(name = "orderamount",nullable = false)
    private Float orderamount;

    // 净利润
    @Column(name = "profitamount",nullable = false)
    private Float profitamount;

    // 客户
    @Column(name = "customer",nullable = false)
    private String customer;

    // 订单信息
    @Column(name = "info",nullable = false)
    private String info;

    // 图片列表
    @Column(name = "images")
    private String images;

    // 文件列表
    @Column(name = "files")
    private String files;

    // 运单号
    @Column(name = "waybill")
    private String waybill;

    // 快递公司
    @Column(name = "express")
    private String express;

    // 快递公司
    @Column(name = "count")
    private Integer count;

    @OneToOne(cascade=CascadeType.MERGE,optional=true)
    @JoinColumn(name = "userid", insertable = false, updatable = false)
    private User User;

    @OneToOne(cascade=CascadeType.MERGE,optional=true)
    @JoinColumn(name = "projectid", insertable = false, updatable = false)
    private Project project;

    public void copy(CrmOrder source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
